home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / gnome-games-data / gnome_sudoku / simple_debug.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  1.4 KB  |  45 lines

  1. # -*- coding: utf-8 -*-
  2. import optparse
  3. import defaults
  4.  
  5. parser = optparse.OptionParser(
  6.     version=defaults.VERSION,
  7.     option_list=[
  8.     optparse.make_option("-v",const=True,action="store_const",
  9.                          dest="debug",help="Print debug information",
  10.                          default=False),
  11.     optparse.make_option("-p",const=True,action="store_const",
  12.                          dest="profile",help="Profile gnome-sudoku",
  13.                          default=False),
  14.     optparse.make_option("-w",const=True,action="store_const",
  15.                          dest="walk",help="Step through program",
  16.                          default=False),
  17.     ]
  18.     )
  19.  
  20. options,args = parser.parse_args()
  21.  
  22.     
  23. # Make a lovely wrapper 
  24. if options.debug:
  25.     def simple_debug (f):
  26.         def _ (self, *args,**kwargs):
  27.             print self.__class__,f.__name__,args,kwargs
  28.             return f(self,*args,**kwargs)
  29.         return _
  30.  
  31. elif options.walk:
  32.     ff = []
  33.     def simple_debug (f):
  34.         def _ (self, *args,**kwargs):
  35.             if (self.__class__,f.__name__) not in ff:
  36.                 print self.__class__,f.__name__,args,kwargs
  37.                 if raw_input('Hit return to step forward (hit i to ignore this function): ')=='i':
  38.                     ff.append((self.__class__,f.__name__))
  39.             return f(self,*args,**kwargs)
  40.         return _
  41.  
  42.  
  43. else:
  44.     def simple_debug (f): return f
  45.